<template>
  <div class="box">
    <div class="title">
      <span class="el-icon-arrow-left" @click="$router.go(-1)"></span>
      {{ $t('Recent Activity') }}
    </div>
    <!-- 查询 -->
    <div class="consume_input">
      <input @focusout="searchUnFocus"
             v-model="searchForm.keyword"
             @change="history"
             @focus="searchFocus"
             class="iconfont"
             :placeholder="showSearchIcon?'\ue630' + $t('home.Search'):''"/>
    </div>
    <!--  -->
    <div v-show="dataList.length>0" class="centent">
      <!-- 标题卡 -->
      <div>
        <div v-for="(item,index) in dataList" :key="index">
          <div class="title_card">
            <!--            <div>支出:${{ item.payout }} 收入: ${{ item.income }}</div>-->
            <el-date-picker
              @change="searchYearMonth"
              v-model="item.yearmonth"
              class="title_card_back"
              type="month"
              :placeholder="$t('Month')">
            </el-date-picker>
          </div>

          <div class="card_back" v-for="(info,subIndex) in item.data" :key="subIndex">
            <div class="card_back_left">
              <img src="../../../../assets/static/Consumption/q1.png" alt="">
              <div>
                <div>{{ info.goods_text }}</div>
                <div>{{ info.create_time }}</div>
              </div>
            </div>
            <span v-show="info.is_consume==='1'" style="color: rgba(119, 200, 24,1)">{{ $t('Orders') }}</span>
            <span v-show="info.is_consume!=='1'" style="color: rgba(255, 38, 38,1)">{{ $t('Scan') }}</span>
          </div>
        </div>

      </div>
    </div>
    <div v-show="dataList.length===0" class="title_card title-select">
      <!--            <div>支出:${{ item.payout }} 收入: ${{ item.income }}</div>-->
      <el-date-picker
        @change="searchYearMonth"
        v-model="yearmonth"
        class="title_card_back"
        type="month"
        :placeholder="$t('Month')">
      </el-date-picker>
    </div>
    <div class="col-wrapper" v-show="dataList.length===0" style="height: 75vh;justify-content: center">
      <div class="height_flex">
        <div class="height_flex_img">
          <img src="../../../../assets/static/activities/box.png" alt="">
          <div class="height_flex_size">{{ $t('home.Noactivityyet!') }}</div>
          <div>{{ $t('home.PastTransactions') }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {history} from '@/api/merbership/activity'
import '@/styles/height_flex.scss'
import '@/styles/flax.css'

export default {
  data() {
    return {
      icon: '\ue630 搜索',
      dataList: [],
      yearmonth: '',
      searchForm: {
        yearmonth: undefined,
        keyword: undefined
      },
      showSearchIcon: true,
    }
  },
  methods: {
    /**
     * 查看活动详情
     * @param info
     */
    checkDetail(info) {
      info.is_consume === '1' ? this.$router.push({
        path: '/listConsumptionDetail',
        query: {id: info.id}
      }) : this.$message.error('无消费记录')
    },
    /**
     * 按月份查找
     * @param val
     */
    searchYearMonth(val) {
      this.searchForm.yearmonth = String(val.getFullYear()) + '-' + String(val.getMonth() + 1)
      this.history()
    },
    /**
     * 失去焦点时
     */
    searchUnFocus() {
      this.showSearchIcon = true
    },
    /**
     * 搜索框获取焦点时
     */
    searchFocus() {
      this.showSearchIcon = false
    },
    /**
     * 时间戳判断
     * @param timeStamp
     * @returns {string}
     */
    checkTime(timeStamp) {
      let timeStr = new Date(Number(timeStamp))
      console.log(timeStr.getFullYear())
      return timeStr.toLocaleString()
    },
    // ---------------- axios ------------------
    /**
     * 活动历史
     */
    history() {
      history(this.$qs.stringify(this.searchForm))
        .then(res => {
          this.dataList = res.data.data
        })
    }
  },
  activated() {
    this.history()
  }
}
</script>

<style scoped>
.title-select {
  margin: 15px;
}

/* 标题 */
.title {
  background-color: #7ac91b;
  color: #fff;
  font-size: 18px;
  text-align: center;
  padding: 15px;
  font-weight: bold;
}

.title .el-icon-arrow-left {
  float: left;
  margin-top: 5px;
}

/*  */
.consume_input {
  margin: 15px;
}

.consume_input input {
  box-shadow: 0 0 10px #ccc;
  width: 98%;
  text-align: center;
  outline: none;
  border: none;
  height: 40px;
  border-radius: 10px;
}

.consume_input input::-webkit-input-placeholder {
  color: #67C41D;
}

/*  */
.centent {
  margin: 15px;
}

/* 标题卡 */
.title_card {
  background-color: rgba(193, 225, 169, 0.5);
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #64BE1D;
  border-radius: 10px;
}

.title_card_back {
  background-color: #fff;
  width: 180px;
  /*padding: 8px;*/
  border-radius: 8px;
}

.title_card_back .el-icon-arrow-down {
  margin-left: 3px;
}

/*  */
.card_back {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  margin: 10px 0;
  padding: 10px;
  border-radius: 10px;
}

.card_back img {
  width: 57px;
}

.card_back_left img {
  width: 45px;
  margin-right: 10px;
  margin-top: 5px;
}

.card_back_left {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: #999999;
  font-weight: normal;
}

.card_back_left > div > div:nth-child(1) {
  margin-bottom: 3px;
  font-size: 13px;
  font-weight: bold;
  color: #333333;
}
</style>
